package me.shan.bit;

import org.junit.Assert;

/**
 * 描述：数组中一种数出现K次其他数出现M次，求出现K次的数
 * M > 1 并且 K < M
 * @author liuchuang
 * @date 2021/6/14
 */
public class KM {

    public static void main(String[] args) {
        int[] bit = new int[32];
        int k = 3;
        int m = 7;
        int[] array = {5, 5, 5, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11, 11, 11, 13, 13, 13, 13, 13, 13, 13};
        for (int value : array) {
            for (int j = 0; j < 32; j++) {
                bit[j] += (value >> j) & 1;
            }
        }
        int ans = 0;
        for (int j = 0; j < bit.length; j++) {
            if (bit[j] % m != 0) {
                ans |= (1 << j);
            }
        }
        Assert.assertEquals(5, ans);
    }

}
